import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import eslint from 'vite-plugin-eslint';
import { codeInspectorPlugin } from 'code-inspector-plugin';
import { publicTypescript, injectScripts } from 'vite-plugin-public-typescript';
import { resolve } from 'path';
import outputArchive from '@hdtd/vite-plugin-output-archive';

const buildName = 'base-react-project';

export default defineConfig({
  plugins: [
    codeInspectorPlugin({
      bundler: 'vite'
    }),
    react(),
    eslint({
      failOnError: false
    }),
    publicTypescript({
      inputDir: './src/assets/inject-js',
      hash: false,
      outputDir: './js'
    }),
    injectScripts((manifest) => [
      {
        attrs: { src: manifest.config },
        injectTo: 'head-prepend'
      }
    ]),
    outputArchive(buildName)
  ],
  build: {
    outDir: buildName
  },
  base: './',
  define: {
    API_RESULT_SUCCEED_CODE: 200
  },
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  }
});
